package o;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Arrays;
import okhttp3.internal.connection.RealConnection;
import okhttp3.internal.connection.StreamAllocation;

class bnq {
    bnq() {
    }

    public static String ˊ(ftz o_ftz) {
        if (o_ftz == null) {
            return "";
        }
        try {
            StreamAllocation streamAllocation = (StreamAllocation) ˎ(o_ftz, "streamAllocation", new Class[0]).invoke(o_ftz, new Object[0]);
            RealConnection connection = streamAllocation.connection();
            if (connection == null) {
                return ((InetSocketAddress) ˊ(ˊ(streamAllocation, "route"), "inetSocketAddress")).getAddress().getHostAddress();
            }
            return ((Socket) ˊ(connection, "socket")).getInetAddress().getHostAddress();
        } catch (NoSuchFieldException e) {
            bnc.ˎ.ˊ("GetServerIpHelper", "NoSuchFieldException:" + e.getMessage());
            return "";
        } catch (NoSuchMethodException e2) {
            bnc.ˎ.ˊ("GetServerIpHelper", "NoSuchMethodException:" + e2.getMessage());
            return "";
        } catch (IllegalArgumentException e3) {
            bnc.ˎ.ˊ("GetServerIpHelper", "IllegalArgumentException:" + e3.getMessage());
            return "";
        } catch (Throwable th) {
            bnc.ˎ.ˊ("GetServerIpHelper", "Throwable:" + th.getMessage());
            return "";
        }
    }

    private static Object ˊ(Object obj, String str) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException {
        Class cls = obj.getClass();
        while (cls != null) {
            try {
                Field declaredField = cls.getDeclaredField(str);
                declaredField.setAccessible(true);
                return declaredField.get(obj);
            } catch (NoSuchFieldException e) {
                cls = cls.getSuperclass();
            }
        }
        throw new NoSuchFieldException();
    }

    public static Method ˎ(Object obj, String str, Class<?>... clsArr) throws NoSuchMethodException {
        Class cls = obj.getClass();
        while (cls != null) {
            try {
                Method declaredMethod = cls.getDeclaredMethod(str, clsArr);
                if (!declaredMethod.isAccessible()) {
                    declaredMethod.setAccessible(true);
                }
                return declaredMethod;
            } catch (NoSuchMethodException e) {
                bnc.ˎ.ˋ("GetServerIpHelper", "GetServerIpHelper get method exception");
                cls = cls.getSuperclass();
            }
        }
        throw new NoSuchMethodException("Method " + str + " with parameters " + Arrays.asList(clsArr) + " not found in " + obj.getClass());
    }
}
